import React, {Component} from 'react';
import {ListView, Text, View, Button, Alert, TouchableOpacity, Image, DatePickerAndroid, Platform} from 'react-native';
import chjStyle from '../../../CustomStyle';

export default class CommonTextItem extends React.Component
{
    constructor(props)
    {
        super(props);
        this.state = {
            v:this.props.valueRenderer?this.props.valueRenderer(this.props.object.value) : this.props.object.value,
            highlight:false,
        };
    }

    render() {
        var valueFontSize = 30;
        var valueTop = 40;
        var numberLines = 3;
        if (this.state.v.length > 36) {
            valueFontSize = 16;
            valueTop = 18;
            numberLines = 4;
        }
        else if (this.state.v.length > 24) {
            valueFontSize = 20;
            valueTop = 23;
        } else if (this.state.v.length > 12) {
            valueFontSize = 28;
            valueTop = 28;
        }

        return (
            <TouchableOpacity
                style={[chjStyle.textItem]}
                onPress={()=>{if (this.props.onClickedListener)this.props.onClickedListener();}}>
                <Text
                    style={{
            position:'absolute',
            color:'#303030',
            textAlign: 'left',
            backgroundColor: 'rgba(0, 0, 0, 0)',
            fontSize: chjStyle.getActualFontSize(30),
            top: chjStyle.getActualSizeInVertical(40),
            left: chjStyle.getActualSizeInHorizontal(40),
            width: chjStyle.getActualSizeInHorizontal(375),
          }}>{this.props.object.name}</Text>
                <Text
                    numberOfLines={numberLines}
                    style={{
            position:'absolute',
            color:this.state.highlight?'#f00':'#303030',
            textAlign: 'right',
            backgroundColor: 'rgba(0, 0, 0, 0)',
            fontSize: chjStyle.getActualFontSize(valueFontSize),
            top: chjStyle.getActualSizeInVertical(valueTop),
            right: chjStyle.getActualSizeInHorizontal(30),
            width: chjStyle.getActualSizeInHorizontal(375),
          }}>{this.state.v.toString()}</Text>
            </TouchableOpacity>
        );
    }
}
